//
//  GGZFBFriendsViewController.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/4/1.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "GGZFBFriendsViewController.h"
#import "GGAddtion.h"
#import "ZFBFriendModel.h"
#import "GGZFBFriendsCell.h"
#import "GGlifeViewController.h"
#import "GGChatViewController.h"
static NSString *cellID = @"cellID";
static NSString *fristID = @"fristID";
@interface GGZFBFriendsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray <ZFBFriendModel *>*listData;
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation GGZFBFriendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"朋友圈";
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadData];
    [self setUI];
}
- (void)setUI{
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:fristID];
    [self.tableView registerClass:[GGZFBFriendsCell class] forCellReuseIdentifier:cellID];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0)
        return 1;
    return self.listData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:fristID forIndexPath:indexPath];
        cell.imageView.image = [UIImage imageNamed:@"APC_timeLineIcon"];
        cell.textLabel.text = @"生活圈";
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        [cell.textLabel sizeToFit];
        /*
               UITableViewCellAccessoryDisclosureIndicator   箭头
               UITableViewCellAccessoryDetailDisclosureButton   箭头加 i
               UITableViewCellAccessoryCheckmark   对号
               UITableViewCellAccessoryDetailButton i
               */
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }
    GGZFBFriendsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    cell.model = self.listData[indexPath.row];
    return cell;
   
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0 && indexPath.row == 0){
        GGlifeViewController *lifeVC = [[GGlifeViewController alloc]init];
        [self.navigationController pushViewController:lifeVC animated:YES];
    }else if(indexPath.section == 1 && indexPath.row == 2){
        GGChatViewController *chatVC = [[GGChatViewController alloc]init];
        [self.navigationController pushViewController:chatVC animated:YES];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section == 0)
        return 10;
    return 0.0;
}
- (void)loadData{
    self.listData = [NSArray gg_arrayModelWithPlistName:@"Friends.plist" withClassName:@"ZFBFriendModel"].mutableCopy;
    [self.tableView reloadData];
}
- (UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, SJHeight, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-IphoneXTabbarH) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 90;
        _tableView.showsVerticalScrollIndicator = NO;
    }
    return _tableView;
}
- (NSMutableArray <ZFBFriendModel *>*)listData{
    if(!_listData){
        _listData = [NSMutableArray array];
    }
    return _listData;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
